package com.qfedu.dtboot.controller;

import com.qfedu.dtboot.entity.SysRole;
import com.qfedu.dtboot.entity.SysUser;
import com.qfedu.dtboot.service.SysRoleService;
import com.qfedu.dtboot.service.SysUserService;
import com.qfedu.dtboot.utils.DataGridResult;
import com.qfedu.dtboot.utils.Query;
import com.qfedu.dtboot.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/sys/user")
public class SysUserController extends AbstractController {
    @Autowired
    private SysUserService sysUserService;
    // 获取用户登入信息
    @GetMapping("/info")
    public R info()
    {
        return R.ok().put("user",getUser());
    }

    @GetMapping("/list")
    @RequiresPermissions(value ={""})
    public DataGridResult getPageList(@RequestParam Map<String,Object> params)
    {
        Query query = new Query(params);
        DataGridResult pageList = sysUserService.getPageList(query);
        return  pageList;
    }

    @PostMapping("/del")
    @RequiresPermissions(value = {""})
    public R delete(@RequestBody Long[] ids)
    {
        sysUserService.deleteBatch(ids);
        return R.ok();
    }
    @PostMapping("/save")
    @RequiresPermissions(value ={"sys:user:save"})
    public R save(@RequestBody SysUser sysUser)
    {
        sysUserService.save(sysUser);
        return R.ok();
    }
    @GetMapping("/info/{userId}")
    @RequiresPermissions(value = {""})
    public R info(@PathVariable("userId") Long userId)
    {
        SysUser sysUser = sysUserService.queryObject(userId);

        return R.ok().put("user",sysUser);
    }

    @PostMapping("/update")
    @RequiresPermissions(value ={"sys:user:update"})
    public R update(@RequestBody SysUser sysUser)
  {
      sysUserService.update(sysUser);
      return R.ok();
  }

}
